﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using YXQ.Service;
using Microsoft.Practices.Unity;
using YXQ.Common.Helper;

namespace YXQ.Manager
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            IUnityContainer container = new UnityContainer();
            ManagerWebInit.InitUnity(container);
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {
            string path = Request.Path;
            string ext = System.IO.Path.GetExtension(path);
            if (!string.IsNullOrEmpty(ext) && !String.IsNullOrEmpty(ext.Trim().ToLower()))
            {
                ext = ext.TrimStart('.').Trim().ToLower();
            }
            if (ext == "css" || ext == "js" || ext == "jpg" || ext == "bmp" || ext == "png" || ext == "gif")
            {
                Server.ClearError();
                return;
            }
            Exception ex = Server.GetLastError().GetBaseException();

            String error = "错误事件\r\n" +
                "发生在:" + Request.Url.ToString() +
                "\r\n错误信息:" + ex.Message.ToString() +
                "\r\nStack Trace:\r\n" + ex.StackTrace.ToString();
            LogHelper.Error(error);
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}